#ifndef VBO_H 
#define VBO_H

#include "Export.h"
#include "IBuffer.h"
#include <GL/glew.h>
#include <iostream>

#define BUFFER_OFFSET(a) ((char*)NULL + (a))
#define STREAM  GL_STREAM_DRAW
#define DYNAMIC GL_DYNAMIC_DRAW
#define STATIC  GL_STATIC_DRAW

namespace glow
{

// mode type 
template< GLenum T, GLenum U, GLenum V >
class SHARED VBO : public IBuffer
{		
	public:
	
		/** Create the VBO */
		VBO<T,U,V>() : firstpush(true)
		{
			glGenBuffers(1, &buf);
			glBindBuffer(V, buf);
		}
		
		/** Destroy the VBO */
		~VBO<T,U,V>()
		{
			glDeleteBuffers(1, &buf);
		}
		
		/** Push data into the buffer */
		void push(void * data, unsigned int size)
		{
			VBO_SIZE=size;
			if (firstpush)
			{
				glBindBuffer(V, buf);
				glBufferData(V, VBO_SIZE, NULL, T);
				glBufferSubData(V,0,size,data);
				glBindBuffer(V, 0);
			}
			else
				std::cout<<"erreur : VBO déja affecté"<<std::endl;
		}

		/** Get the type of data stored */
		GLenum getBufferType() const
		{
			return U;
		}

		/** get the Buffer size */
		unsigned int getBufferSize(){ return VBO_SIZE; }
		
		/** \return OpenGL buffer id */
		GLuint getGLID() const { return buf; }
		
	private:
	
		GLuint buf;
		bool firstpush;
		unsigned int VBO_SIZE;
};

}
#endif    

